/**
 * 元数据及路由匹配
 */

var routes = [
    {
        path: "/",
        component: {
            template: `
            <div>
                <h1>首页</h1>
            </div>
            `
        }
    },
    {
        path: "/login",
        component: {

            template: `
            <div>
                登录
            </div>
            `,
        },

    },
    {
        path: "/article",
        meta : {
            loginRequired : true
        },
        component: {

            template: `
                <div>
                    帖子管理
                </div>
            `
        },

    },

]
var vueRouter = new VueRouter({
    routes: routes
})
vueRouter.beforeEach(function(to, from, next){
    var login = false
    //console.log(to)
    if(!login&&to.matched.some(function(item){
            //console.log(item)
            return item.meta.loginRequired
        })){
        next("/login") 
    } else {
        next()
    }
    
})

var app = new Vue({
    el: "#app",
    router: vueRouter,
})